package com.unisound.tracelog.common.model.dto;

import java.io.Serializable;
import java.util.List;

public class ResultDTO<T extends Serializable> implements Serializable {
    private static final long serialVersionUID = 1L;

    private String code;
    private String message;
    private boolean success;
    private T data;
    private List<T> dataList;

    private ResultDTO() {
    }

    public ResultDTO(String code, String message, boolean success, T data) {
        this.code = code;
        this.message = message;
        this.success = success;
        this.data = data;
    }

    public ResultDTO(String code, String message, boolean success, List<T> dataList) {
        this.code = code;
        this.message = message;
        this.success = success;
        this.dataList = dataList;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }

    public static <T extends Serializable> ResultDTO success(T data) {
        return new ResultDTO(null, null, true, data);
    }

    public static <T extends Serializable> ResultDTO success(List<T> dataList) {
        return new ResultDTO(null, null, true, dataList);
    }

    public static <T extends Serializable> ResultDTO success() {
        return success((Serializable) null);
    }

    public static <T extends Serializable> ResultDTO fail(String code, String message) {
        return new ResultDTO(code, message, false, (Serializable) null);
    }

    public static boolean success(ResultDTO resultDTO) {
        if (resultDTO == null) return false;
        return resultDTO.success;
    }

}
